package dcdroplet;

// Import Java JDK Classes
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Date;

/**
* @author dca
*/
public class FileAppenderProperties extends AppenderProperties {
	@Override
	public void log(String tag, String msg, String msgFmt, String className, long timeStamp) {
		try {
			PrintStream out = new PrintStream(new FileOutputStream(this.getFile(), true));

			out.println(
				msgFmt.replace("${appender_name}", this.getAppenderName())
				      .replace("${class_name}",    className)
				      .replace("${tag_name}",      tag)
				      .replace("${date}",          DATE.format(new Date(timeStamp)))
				      .replace("${time}",          TIME.format(new Date(timeStamp)))
				      .replace("${message}",       msg)
			);

			out.flush();
			out.close();
		} catch(FileNotFoundException fileExc) {
			System.err.printf("File not found: %s, for appender: %s%n", this.getFileDefinition(), this.getAppenderName());
		} // END try/catch
	} // END log
} // END class FileAppenderProperties
